<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <link rel="stylesheet" type="text/css" href="index_style.css"/>
        <title>PDF list</title>
    </head>
        <?php
// Connect to the database

                $conn = @mysql_connect("localhost" , "root", "") or die(mysql_error());
                    mysql_select_db("db_name") or die(mysql_error());

 
// Query for a list of all existing files
$query = 'SELECT `file_name`, `file_path`, `size` , `type` , `date`  FROM `pdfs`';
$result = mysql_query($query) or die (my_sql_error());

// Check if it was successfull
    // Make sure there are some files in the database
    if(!mysql_num_rows($result))  {
        echo '<p>There are no files in the database</p>';
    }
    else {
        // Print the top of a table
        echo '<table width="100%">
                <tr>
                    <td><b>Name</b></td>
                    <td><b>Type</b></td>
                    <td><b>Size (bytes)</b></td>
                    <td><b>Created</b></td>
                    <td><b>Download</b></td>
                    <td><b>View</b></td>
                </tr>';
        // Print each file
        while($row = mysql_fetch_assoc($result)) {
            echo "
                <tr>
                    <td>{$row['file_name']}</td>
                    <td>{$row['type']}</td>
                    <td>{$row['size']}</td>
                    <td>{$row['date']}</td>
                    <td><a href='download.php?file_name={$row['file_name']}'>Download</a></td>
                    <td><a target='_blank' href='viewfile.php?file_name={$row['file_name']}'>View</a></td>           
                    </tr>"; 
        }
        // Close table
        echo '</table>';
    
}


//  link to return back to the main page
echo '<p>Click <a href="index.php">here</a> to go back</p>';
?>        
    </body>
</html>
